python脚本设置超时机制系统时间的方法 | 您所在的位置:网站首页 › python 设置超时时间 › python脚本设置超时机制系统时间的方法 |
#-*- coding:utf-8 -*-
import socket
import struct
import time
import win32api
import os
import re
def getTime(TimeServerAddresses):
TIME_1970 = 2208988800L
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.settimeout(3)
data = '\x1b' + 47 * '\0'
#TimeServer_ip=socket.gethostbyname('cn.pool.ntp.org')
#TimeServer_ip='202.118.1.130'
Port=123
for address in TimeServerAddresses:
success=False
count=0
while not success and count 1:
# break
#TimeServer=address
if __name__ == '__main__':
addresses=getServerIP()
now_time=getTime(addresses)
setSystemTime(now_time)
print "%d-%d-%d %d:%d:%d" % time.localtime(now_time)[:6]
以上就是本文的全部内容,希望对大家的学习有所帮助。 微信分享![]() 声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系[email protected]核实处理。 相关标签:python 系统时间 超时上一篇:Python实现字典依据value排序下一篇:Python中方法链的使用方法 |
CopyRight 2018-2019 实验室设备网 版权所有 |